package com.cskaoyan._05stringbuffer;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/16 14:41
 **/

public class APITest {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();
        // 获取功能
        //public int capacity() 返回当前容量,数组的长度,理论值
        //public int length() 返回长度(字符的个数),实际值
        System.out.println("sb.capacity() = " + sb.capacity());
        System.out.println("sb.length() = " + sb.length());

        //添加功能
        //public StringBuffer append(String s) 将指定的字符串(其他类型有重载方法)追加到此字符序列的尾部
        StringBuffer sb2 = sb.append("abc");
        System.out.println("sb2 = " + sb2);


        //在指定位置把任意类型的数据插入到字符串缓冲区里面
        //public StringBuffer insert(int offset,String str)
        StringBuffer sb3 = sb2.insert(1, "yyds");
        System.out.println("sb3 = " + sb3);


        //删除功能
        //public StringBuffer deleteCharAt(int index)：删除指定位置的字符
        //public StringBuffer delete(int start,int end)：删除从指定位置开始指定位置结束的内容
        System.out.println(sb3.deleteCharAt(1));
        System.out.println("sb3.delete(1, 4) = " + sb3.delete(1, 4));

        //替换功能
        //使用给定String中的字符替换词序列的子字符串中的字符
        //public StringBuffer replace(int start,int end,String str)
        System.out.println("sb3.replace(0, 1, \"aaaa\") = " + sb3.replace(0, 1, "aaaa"));

        //反转功能
        //public StringBuffer reverse()：将此字符序列用其反转形式取代，返回对象本身
        StringBuffer stringBuffer = new StringBuffer("abcd");
        System.out.println("stringBuffer.reverse() = " + stringBuffer.reverse());
    }
}
